package graphicalUserInterface;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
//@author U096819H
public class ConfirmPrompt extends Dialog {

	protected Shell shell;
	private int count;
	private boolean result;


	//@author U096819H
	public ConfirmPrompt(Shell parent, int style) {
		super(parent, style);
		setText("Notification");
	}

	//@author U096819H
	public boolean open(String message) {
		result = false;
		result = createContents(message);
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	//@author U096819H
	private boolean createContents(String message) {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(300, 129);
		shell.setText(getText());
		shell.setLayout(new FormLayout());

		Composite composite = new Composite(shell, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		FormData fd_composite = new FormData();
		fd_composite.bottom = new FormAttachment(0, 91);
		fd_composite.top = new FormAttachment(0, 10);
		fd_composite.left = new FormAttachment(0, 10);
		fd_composite.right = new FormAttachment(0, 284);
		composite.setLayoutData(fd_composite);

		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				true, 2, 1));
		lblNewLabel.setText(message);

		Button btnYes = new Button(composite, SWT.NONE);
		btnYes.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				result = true;
				shell.close();
			}
		});
		GridData gd_btnYes = new GridData(SWT.RIGHT, SWT.TOP, true, true, 1, 1);
		gd_btnYes.widthHint = 85;
		btnYes.setLayoutData(gd_btnYes);
		btnYes.setText("Yes");

		Button btnNo = new Button(composite, SWT.NONE);
		btnNo.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				result = false;
				shell.close();
			}
		});
		GridData gd_btnNo = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
		gd_btnNo.widthHint = 85;
		btnNo.setLayoutData(gd_btnNo);
		btnNo.setText("No");
		
		return result;
	}
}
